//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.bgs.service.impl;

import com.bgs.entity.Commodityorder;
import com.bgs.entity.Recyclingorder;
import com.bgs.entity.Selection;
import com.bgs.entity.User;
import com.bgs.mapper.CommodityMapper;
import com.bgs.service.CommodityService;
import com.bgs.vo.Dingdanchaxun;
import com.bgs.vo.Kucun;
import com.bgs.vo.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommodityServiceImpl implements CommodityService {
    @Autowired
    private CommodityMapper commodityMapper;

    public CommodityServiceImpl() {
    }

    public PageInfo<Kucun> pageList(Page page, String commodityNumber, String commodityName, Integer storeId) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        PageInfo<Kucun> kucunPageInfo = new PageInfo(this.commodityMapper.like(commodityNumber, commodityName, storeId));
        return kucunPageInfo;
    }

    public int songhuo(Kucun kucun) {
        Integer kcid = kucun.getCsId();
        Integer select = kucun.getSelectionId();
        Integer num = kucun.getNum();
        Integer stock = kucun.getStock();
        Selection selection = this.commodityMapper.selectsj(select);
        Integer selectStock = selection.getStock();
        Integer selectionid = selection.getSelectionId();
        if (selectStock > num) {
            Integer jian = selectStock - num;
            Integer jia = stock + num;
            this.commodityMapper.upselectionjia(selectionid, jian);
            this.commodityMapper.upselectionjian(kcid, jia);
            return 1;
        } else {
            return 0;
        }
    }

    public PageInfo<Recyclingorder> pageListhuichou(Page page, Dingdanchaxun dingdanchaxun) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        PageInfo<Recyclingorder> kucunPageInfo = new PageInfo(this.commodityMapper.dingdanlike(dingdanchaxun.getNumber(), dingdanchaxun.getPhone(), dingdanchaxun.getRoType(), dingdanchaxun.getStoreId()));
        return kucunPageInfo;
    }

    public User qsid(Recyclingorder recyclingorder) {
        Integer shid = recyclingorder.getShid();
        User user = this.commodityMapper.seleid(shid);
        return user;
    }

    public List<User> lisyqs(Integer storeId) {
        return this.commodityMapper.lisyqs(storeId);
    }

    public void xg(Integer userId, Integer roId) {
        this.commodityMapper.xg(userId, roId);
    }

    public void updatezt(Integer roId) {
        this.commodityMapper.updatezt(roId);
    }

    public PageInfo<Commodityorder> pageListduihuan(Page page, String number, Integer deliveryMethod, Integer storeId) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        PageInfo<Commodityorder> kucunPageInfo = new PageInfo(this.commodityMapper.pageListduihuan(number, deliveryMethod, storeId));
        return kucunPageInfo;
    }

    public List<Kucun> qhcx(Integer commodityId) {
        return this.commodityMapper.qhkc(commodityId);
    }

    public int qupdate(Integer coId) {
        return this.commodityMapper.qupdate(coId);
    }

    public List<Recyclingorder> list2(Integer storeId) {
        return this.commodityMapper.list2(storeId);
    }
}